#ifndef _WX_GRAPHICS_H_
#define _WX_GRAPHICS_H_

#include "wx/defs.h"

#if wxUSE_GRAPHICS_CONTEXT

#include "wx/geometry.h"
#include "wx/dynarray.h"

class WXDLLIMPEXP_CORE wxWindowDC;
class WXDLLIMPEXP_CORE wxMemoryDC;
class WXDLLIMPEXP_CORE wxGraphicsContext;
class WXDLLIMPEXP_CORE wxGraphicsPath;
class WXDLLIMPEXP_CORE wxGraphicsMatrix;
class WXDLLIMPEXP_CORE wxGraphicsFigure;
class WXDLLIMPEXP_CORE wxGraphicsRenderer;
class WXDLLIMPEXP_CORE wxGraphicsPen;
class WXDLLIMPEXP_CORE wxGraphicsBrush;
class WXDLLIMPEXP_CORE wxGraphicsFont;
class WXDLLIMPEXP_CORE wxGraphicsBitmap;

class WXDLLIMPEXP_CORE wxGraphicsObjectRefData : public wxObjectRefData {
  public :
    wxGraphicsObjectRefData( wxGraphicsRenderer* renderer );
    wxGraphicsObjectRefData( const wxGraphicsObjectRefData* data );
    wxGraphicsRenderer* GetRenderer() const ;
    virtual wxGraphicsObjectRefData* Clone() const ;

  protected :
    wxGraphicsRenderer* m_renderer;
} ;

class WXDLLIMPEXP_CORE wxGraphicsObject : public wxObject {
  public :
    wxGraphicsObject() ;
    #if wxABI_VERSION >= 20810
    wxGraphicsObject( const wxGraphicsObject& other ) : wxObject( other ) {}
    wxGraphicsObject& operator= ( const wxGraphicsObject & other ) { Ref( other ); return *this;}
    #endif
    wxGraphicsObject( wxGraphicsRenderer* renderer ) ;
    virtual ~wxGraphicsObject() ;

    bool IsNull() const ;

    // returns the renderer that was used to create this instance, or NULL if it has not been initialized yet
    wxGraphicsRenderer* GetRenderer() const ;
    wxGraphicsObjectRefData* GetGraphicsData() const ;
  protected :
    virtual wxObjectRefData* CreateRefData() const;
    virtual wxObjectRefData* CloneRefData( const wxObjectRefData* data ) const;

    DECLARE_DYNAMIC_CLASS( wxGraphicsObject )
} ;

class WXDLLIMPEXP_CORE wxGraphicsPen : public wxGraphicsObject {
  public :
    wxGraphicsPen() {}
    #if wxABI_VERSION >= 20810
    wxGraphicsPen( const wxGraphicsPen& other ) : wxGraphicsObject( other ) {}
    wxGraphicsPen& operator= ( const wxGraphicsPen & other ) { Ref( other ); return *this;}
    #endif
    virtual ~wxGraphicsPen() {}
  private :
    DECLARE_DYNAMIC_CLASS( wxGraphicsPen )
} ;

extern WXDLLEXPORT_DATA( wxGraphicsPen ) wxNullGraphicsPen;

class WXDLLIMPEXP_CORE wxGraphicsBrush : public wxGraphicsObject {
  public :
    wxGraphicsBrush() {}
    #if wxABI_VERSION >= 20810
    wxGraphicsBrush( const wxGraphicsBrush& other ) : wxGraphicsObject( other ) {}
    wxGraphicsBrush& operator= ( const wxGraphicsBrush & other ) { Ref( other ); return *this;}
    #endif
    virtual ~wxGraphicsBrush() {}
  private :
    DECLARE_DYNAMIC_CLASS( wxGraphicsBrush )
} ;

extern WXDLLEXPORT_DATA( wxGraphicsBrush ) wxNullGraphicsBrush;

class WXDLLIMPEXP_CORE wxGraphicsFont : public wxGraphicsObject {
  public :
    wxGraphicsFont() {}
    #if wxABI_VERSION >= 20810
    wxGraphicsFont( const wxGraphicsFont& other ) : wxGraphicsObject( other ) {}
    wxGraphicsFont& operator= ( const wxGraphicsFont & other ) { Ref( other ); return *this;}
    #endif
    virtual ~wxGraphicsFont() {}
  private :
    DECLARE_DYNAMIC_CLASS( wxGraphicsFont )
} ;

extern WXDLLEXPORT_DATA( wxGraphicsFont ) wxNullGraphicsFont;

class WXDLLIMPEXP_CORE wxGraphicsBitmap : public wxGraphicsObject {
  public :
    wxGraphicsBitmap() {}
    #if wxABI_VERSION >= 20810
    wxGraphicsBitmap( const wxGraphicsBitmap& other ) : wxGraphicsObject( other ) {}
    wxGraphicsBitmap& operator= ( const wxGraphicsBitmap & other ) { Ref( other ); return *this;}
    #endif
    virtual ~wxGraphicsBitmap() {}
  private :
    DECLARE_DYNAMIC_CLASS( wxGraphicsBitmap )
} ;

extern WXDLLEXPORT_DATA( wxGraphicsBitmap ) wxNullGraphicsBitmap;

class WXDLLIMPEXP_CORE wxGraphicsMatrixData : public wxGraphicsObjectRefData {
  public :
    wxGraphicsMatrixData( wxGraphicsRenderer* renderer ) :
      wxGraphicsObjectRefData( renderer ) {}

    virtual ~wxGraphicsMatrixData() {}

    // concatenates the matrix
    virtual void Concat( const wxGraphicsMatrixData *t ) = 0;

    // sets the matrix to the respective values
    virtual void Set( wxDouble a = 1.0, wxDouble b = 0.0, wxDouble c = 0.0, wxDouble d = 1.0,
                      wxDouble tx = 0.0, wxDouble ty = 0.0 ) = 0;

    // gets the component valuess of the matrix
    virtual void Get( wxDouble* a = NULL, wxDouble* b = NULL,  wxDouble* c = NULL,
                      wxDouble* d = NULL, wxDouble* tx = NULL, wxDouble* ty = NULL ) const = 0;

    // makes this the inverse matrix
    virtual void Invert() = 0;

    // returns true if the elements of the transformation matrix are equal ?
    virtual bool IsEqual( const wxGraphicsMatrixData* t ) const  = 0;

    // return true if this is the identity matrix
    virtual bool IsIdentity() const = 0;

    //
    // transformation
    //

    // add the translation to this matrix
    virtual void Translate( wxDouble dx, wxDouble dy ) = 0;

    // add the scale to this matrix
    virtual void Scale( wxDouble xScale, wxDouble yScale ) = 0;

    // add the rotation to this matrix (radians)
    virtual void Rotate( wxDouble angle ) = 0;

    //
    // apply the transforms
    //

    // applies that matrix to the point
    virtual void TransformPoint( wxDouble *x, wxDouble *y ) const = 0;

    // applies the matrix except for translations
    virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const = 0;

    // returns the native representation
    virtual void * GetNativeMatrix() const = 0;
} ;

class WXDLLIMPEXP_CORE wxGraphicsMatrix : public wxGraphicsObject {
  public :
    wxGraphicsMatrix() {}
    #if wxABI_VERSION >= 20810
    wxGraphicsMatrix( const wxGraphicsMatrix& other ) : wxGraphicsObject( other ) {}
    wxGraphicsMatrix& operator= ( const wxGraphicsMatrix & other ) { Ref( other ); return *this;}
    #endif

    virtual ~wxGraphicsMatrix() {}

    // concatenates the matrix
    virtual void Concat( const wxGraphicsMatrix *t );
    void Concat( const wxGraphicsMatrix &t ) { Concat( &t ); }

    // sets the matrix to the respective values
    virtual void Set( wxDouble a = 1.0, wxDouble b = 0.0, wxDouble c = 0.0, wxDouble d = 1.0,
                      wxDouble tx = 0.0, wxDouble ty = 0.0 );

    // gets the component valuess of the matrix
    virtual void Get( wxDouble* a = NULL, wxDouble* b = NULL,  wxDouble* c = NULL,
                      wxDouble* d = NULL, wxDouble* tx = NULL, wxDouble* ty = NULL ) const;

    // makes this the inverse matrix
    virtual void Invert();

    // returns true if the elements of the transformation matrix are equal ?
    virtual bool IsEqual( const wxGraphicsMatrix* t ) const;
    bool IsEqual( const wxGraphicsMatrix& t ) const { return IsEqual( &t ); }

    // return true if this is the identity matrix
    virtual bool IsIdentity() const;
    virtual void Translate( wxDouble dx, wxDouble dy );

    // add the scale to this matrix
    virtual void Scale( wxDouble xScale, wxDouble yScale );

    // add the rotation to this matrix (radians)
    virtual void Rotate( wxDouble angle );
    virtual void TransformPoint( wxDouble *x, wxDouble *y ) const;
    virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const;
    virtual void * GetNativeMatrix() const;

    const wxGraphicsMatrixData* GetMatrixData() const
    { return ( const wxGraphicsMatrixData* ) GetRefData(); }
    wxGraphicsMatrixData* GetMatrixData() { return ( wxGraphicsMatrixData* ) GetRefData(); }

  private :
    DECLARE_DYNAMIC_CLASS( wxGraphicsMatrix )
} ;

extern WXDLLEXPORT_DATA( wxGraphicsMatrix ) wxNullGraphicsMatrix;

class WXDLLIMPEXP_CORE wxGraphicsPathData : public wxGraphicsObjectRefData {
  public :
    wxGraphicsPathData( wxGraphicsRenderer* renderer ) : wxGraphicsObjectRefData( renderer ) {}
    virtual ~wxGraphicsPathData() {}
    virtual void MoveToPoint( wxDouble x, wxDouble y ) = 0;
    virtual void AddLineToPoint( wxDouble x, wxDouble y ) = 0;
    virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y ) = 0;
    virtual void AddPath( const wxGraphicsPathData* path ) = 0;
    virtual void CloseSubpath() = 0;
    virtual void GetCurrentPoint( wxDouble* x, wxDouble* y ) const = 0;
    virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ) = 0;
    virtual void AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y );
    virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
    virtual void AddCircle( wxDouble x, wxDouble y, wxDouble r );
    virtual void AddArcToPoint( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, wxDouble r ) ;
    virtual void AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
    virtual void AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius );
    virtual void * GetNativePath() const = 0;
    virtual void UnGetNativePath( void *p ) const = 0;
    virtual void Transform( const wxGraphicsMatrixData* matrix ) = 0;
    virtual void GetBox( wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h ) const = 0;
    virtual bool Contains( wxDouble x, wxDouble y, int fillStyle = wxODDEVEN_RULE ) const = 0;
};

class WXDLLIMPEXP_CORE wxGraphicsPath : public wxGraphicsObject {
  public :
    wxGraphicsPath()  {}
    #if wxABI_VERSION >= 20810
    wxGraphicsPath( const wxGraphicsPath& other ) : wxGraphicsObject( other ) {}
    wxGraphicsPath& operator= ( const wxGraphicsPath & other ) { Ref( other ); return *this;}
    #endif
    virtual ~wxGraphicsPath() {}
    virtual void MoveToPoint( wxDouble x, wxDouble y );
    void MoveToPoint( const wxPoint2DDouble& p );
    virtual void AddLineToPoint( wxDouble x, wxDouble y );
    void AddLineToPoint( const wxPoint2DDouble& p );
    virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y ) ;
    void AddCurveToPoint( const wxPoint2DDouble& c1, const wxPoint2DDouble& c2, const wxPoint2DDouble& e );
    virtual void AddPath( const wxGraphicsPath& path );
    virtual void CloseSubpath() ;
    virtual void GetCurrentPoint( wxDouble* x, wxDouble* y ) const;
    wxPoint2DDouble GetCurrentPoint() const;
    virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ) ;
    void AddArc( const wxPoint2DDouble& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise );
    virtual void AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y );
    virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
    virtual void AddCircle( wxDouble x, wxDouble y, wxDouble r );
    virtual void AddArcToPoint( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, wxDouble r ) ;
    virtual void AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
    virtual void AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius );
    virtual void * GetNativePath() const;
    virtual void UnGetNativePath( void *p )const;
    virtual void Transform( const wxGraphicsMatrix& matrix );
    virtual void GetBox( wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h )const;
    wxRect2DDouble GetBox()const;

    virtual bool Contains( wxDouble x, wxDouble y, int fillStyle = wxODDEVEN_RULE )const;
    bool Contains( const wxPoint2DDouble& c, int fillStyle = wxODDEVEN_RULE )const;

    const wxGraphicsPathData* GetPathData() const
    { return ( const wxGraphicsPathData* ) GetRefData(); }
    wxGraphicsPathData* GetPathData() { return ( wxGraphicsPathData* ) GetRefData(); }

  private :
    DECLARE_DYNAMIC_CLASS( wxGraphicsPath )
} ;

extern WXDLLEXPORT_DATA( wxGraphicsPath ) wxNullGraphicsPath;

class WXDLLIMPEXP_CORE wxGraphicsContext : public wxGraphicsObject {
  public:
    wxGraphicsContext( wxGraphicsRenderer* renderer );
    virtual ~wxGraphicsContext();
    static wxGraphicsContext* Create( const wxWindowDC& dc ) ;
    static wxGraphicsContext* CreateFromNative( void * context ) ;
    static wxGraphicsContext* CreateFromNativeWindow( void * window ) ;
    static wxGraphicsContext* Create( wxWindow* window ) ;
    static wxGraphicsContext * Create();
    wxGraphicsPath CreatePath() const;
    virtual wxGraphicsPen CreatePen( const wxPen& pen ) const;
    virtual wxGraphicsBrush CreateBrush( const wxBrush& brush ) const;
    virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
        const wxColour&c1, const wxColour&c2 ) const;
    virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
        const wxColour &oColor, const wxColour &cColor ) const;

    // sets the font
    virtual wxGraphicsFont CreateFont( const wxFont &font, const wxColour &col = *wxBLACK ) const;

    #if wxABI_VERSION >= 20809
    wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) const;
    #endif
    virtual wxGraphicsMatrix CreateMatrix( wxDouble a = 1.0, wxDouble b = 0.0, wxDouble c = 0.0, wxDouble d = 1.0,
                                           wxDouble tx = 0.0, wxDouble ty = 0.0 ) const;
    virtual void PushState() = 0;
    virtual void PopState() = 0;
    virtual void Clip( const wxRegion &region ) = 0;
    virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
    virtual void ResetClip() = 0 ;
    virtual void * GetNativeContext() = 0;
    virtual int GetLogicalFunction() const { return m_logicalFunction; }
    virtual bool SetLogicalFunction( int function ) ;
    virtual void Translate( wxDouble dx, wxDouble dy ) = 0;
    virtual void Scale( wxDouble xScale, wxDouble yScale ) = 0;
    virtual void Rotate( wxDouble angle ) = 0;
    virtual void ConcatTransform( const wxGraphicsMatrix& matrix ) = 0;
    virtual void SetTransform( const wxGraphicsMatrix& matrix ) = 0;
    virtual wxGraphicsMatrix GetTransform() const = 0;
    virtual void SetPen( const wxGraphicsPen& pen );
    void SetPen( const wxPen& pen );
    virtual void SetBrush( const wxGraphicsBrush& brush );
    void SetBrush( const wxBrush& brush );
    virtual void SetFont( const wxGraphicsFont& font );
    void SetFont( const wxFont& font, const wxColour& colour );
    virtual void StrokePath( const wxGraphicsPath& path ) = 0;
    virtual void FillPath( const wxGraphicsPath& path, int fillStyle = wxODDEVEN_RULE ) = 0;
    virtual void DrawPath( const wxGraphicsPath& path, int fillStyle = wxODDEVEN_RULE );
    virtual void DrawText( const wxString &str, wxDouble x, wxDouble y ) = 0;
    virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle );
    virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, const wxGraphicsBrush& backgroundBrush ) ;
    virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle, const wxGraphicsBrush& backgroundBrush );
    virtual void GetTextExtent( const wxString &text, wxDouble *width, wxDouble *height,
                                wxDouble *descent, wxDouble *externalLeading ) const  = 0;
    virtual void GetPartialTextExtents( const wxString& text, wxArrayDouble& widths ) const = 0;
    #if wxABI_VERSION >= 20809
    void DrawGraphicsBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
    #endif

    virtual void DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
    virtual void DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
    virtual void StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2 );
    virtual void StrokeLines( size_t n, const wxPoint2DDouble *points );
    virtual void StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints );
    virtual void DrawLines( size_t n, const wxPoint2DDouble *points, int fillStyle = wxODDEVEN_RULE );
    virtual void DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
    virtual void DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
    virtual void DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius );
    virtual bool ShouldOffset() const { return false; }

  protected :

    wxGraphicsPen m_pen;
    wxGraphicsBrush m_brush;
    wxGraphicsFont m_font;
    int m_logicalFunction;

  private :
    DECLARE_NO_COPY_CLASS( wxGraphicsContext )
    DECLARE_ABSTRACT_CLASS( wxGraphicsContext )
};

class WXDLLIMPEXP_CORE wxGraphicsRenderer : public wxObject {
  public :
    wxGraphicsRenderer() {}
    virtual ~wxGraphicsRenderer() {}
    static wxGraphicsRenderer* GetDefaultRenderer();

    #if wxABI_VERSION >= 20811
    static wxGraphicsRenderer* GetCairoRenderer();
    #endif
    virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc ) = 0 ;
    virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ) = 0;
    virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ) = 0;
    virtual wxGraphicsContext * CreateContext( wxWindow* window ) = 0;
    virtual wxGraphicsContext * CreateMeasuringContext() = 0;
    virtual wxGraphicsPath CreatePath() = 0;
    virtual wxGraphicsMatrix CreateMatrix( wxDouble a = 1.0, wxDouble b = 0.0, wxDouble c = 0.0, wxDouble d = 1.0,
                                           wxDouble tx = 0.0, wxDouble ty = 0.0 ) = 0;
    virtual wxGraphicsPen CreatePen( const wxPen& pen ) = 0 ;
    virtual wxGraphicsBrush CreateBrush( const wxBrush& brush ) = 0 ;
    virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
        const wxColour&c1, const wxColour&c2 ) = 0;
    virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
        const wxColour &oColor, const wxColour &cColor ) = 0;
    virtual wxGraphicsFont CreateFont( const wxFont &font, const wxColour &col = *wxBLACK ) = 0;

    #if wxABI_VERSION >= 20809
    wxGraphicsBitmap CreateBitmap( const wxBitmap &bmp );
    #endif

  private :
    DECLARE_NO_COPY_CLASS( wxGraphicsRenderer )
    DECLARE_ABSTRACT_CLASS( wxGraphicsRenderer )
} ;

#endif
#endif
